/**
 * UILess 接口列表
 */

const { UILessConfig } = window;
const { host: UILessHost, orgId } = UILessConfig;

function uiless({ url, host, ...others }) {
  return {
    url: `${host || UILessHost}${url}`,
    headers: {
      'X-Tenant-Id': `${orgId}`,
      Authorization: `Bearer ${UILessConfig.accessToken}`,
      'X-app-id': `${UILessConfig.appId}`,
    },
    withCredentials: true,
    // name: '获取当前企业信息',
    noErrorToast: true,
    ...others,
  };
}

const apimap = [
  {
    id: 'organization.info',
    url: `/api/ajax/teambition/api/organizations/${orgId}`,
    // name: '获取当前企业信息',
  },
  {
    id: 'organization.member',
    url: '/api/ajax/teambition/api/organizations/{{orgId}}/members',
    // name: '查询企业成员信息',
  },
  {
    id: 'global.newbie.task.switch',
    url: '/api/ajax/flow/properties/public?key={{{key}}}',
    // name: '全局新手任务开关',
  },
  // 获取全部应用插件列表，用于判断库内文档应用是否开启
  {
    id: 'uiless.getAllExtension',
    url: '/api/organization/{{organizationId}}/object/{{objectId}}/extensions',
  },
  {
    id: 'uiless.enableExtension',
    url: '/api/organization/{{organizationId}}/object/{{objectId}}/app/{{appId}}/enable',
    method: 'put',
  },
  {
    id: 'api.teams',
    url: '/api/teams',
  },
  {
    id: 'uiless-get-memberAndteams',
    url: '/api/teams/{{id}}/memberAndTeams',
  },
  {
    id: 'newbieTask.qrcode',
    url: '/uiless/api/app/codeup/config',
    host: 'https://devops.aliyun.com',
    // name: '小微企业二维码',
  },
  {
    id: 'reattemptCodeBuild',
    // name: '手动触发codeup的扫描重试',
    url: '/api/ajax/codeup/api/v4/projects/{{projectId}}/build/manual/reattempt?build_result_id={{build_result_id}}',
    // method: 'post',
  },
  {
    id: 'uiless.featureflag.put',
    url: '/support/api/v1/me/featureflag',
    method: 'put',
    // name: '底座功能开关',
  },
];

const uiliessApiMap = apimap.map((item) => uiless(item));

export default uiliessApiMap;
